package 
{
	import flash.events.MouseEvent;
	import flash.ui.MouseCursor;
	import flash.ui.Mouse;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	/**
	 * ...
	 * @author DarkGoodWIN
	 */
	public class MoveScrolling extends BaseScrolling 
	{
		private var ScrolRect: Trect = null;
		private var MainRect: Trect = null;
				
		public override function UpdateScrollView(): void
		{
			var H: Number = 0;
			var AllH: Number = fCont.AllCtrlsHeight();
			if (AllH > 0)
				H = fCont.Height / AllH;
			trace(H);
			ScrolRect.Height = H * fCont.Height;
			
			ScrolRect.Y = fCont.Y + fCont.BeforeFirstItemHeight() * H;
			trace(ScrolRect.Y, fCont.BeforeFirstItemHeight() * H, fCont.FirstItemIndex);
		}
		
		private function MainClick(e: MouseEvent): void
		{
			trace(e.stageY, ScrolRect.Y + ScrolRect.Height);
			if (fCont.AllCtrlsHeight() <= fCont.Height)
				return;
			if (e.stageY > ScrolRect.Y + ScrolRect.Height)
				fCont.List2Right()
			else
				fCont.List2Left();
		}
		
		private function ScrollDown(e: MouseEvent): void
		{
			(ScrolRect.Ctrl as Sprite).startDrag(false, new Rectangle(MainRect.X, MainRect.Y, 0, MainRect.Height - ScrolRect.Height));			
			TControl.InDrag = true;
		}
		
		private function ScrollUp(e: MouseEvent): void
		{	
			(ScrolRect.Ctrl as Sprite).stopDrag();
			Mouse.cursor = MouseCursor.ARROW;
			TControl.InDrag = false;
		}
		
		private function ScrollMove(e: MouseEvent): void
		{
			Mouse.cursor = MouseCursor.BUTTON;
			if (!(e.buttonDown))
				ScrollUp(e);
		}
		
		public function MoveScrolling(Cont: TBaseContainer): void
		{
			super(Cont);
			MainRect = new Trect(Cont.fParent, 0x505050, Cont.X + Cont.Width - 20, Cont.Y, 15, Cont.Height);
			ScrolRect = new Trect(Cont.fParent, 0x101010, Cont.X + Cont.Width - 20, Cont.Y, 15, 1);
			(ScrolRect.Ctrl as Sprite).useHandCursor = true;
			
			ScrolRect.addEventListener(MouseEvent.MOUSE_DOWN, ScrollDown);
			ScrolRect.addEventListener(MouseEvent.MOUSE_UP, ScrollUp);
			ScrolRect.addEventListener(MouseEvent.MOUSE_MOVE, ScrollMove);

			MainRect.addEventListener(MouseEvent.CLICK, MainClick);
		}
	}
	
}